package com.zbkj.common.enums;

import cn.hutool.core.util.StrUtil;

/**
 * 品牌商枚举
 * +----------------------------------------------------------------------
 * @author xiaolic
 * +----------------------------------------------------------------------
 */
public enum BrandEnum {
    // 崇仁
    CR("cr.brand", "cr-merchant.brand", "cr-admin.brand", 7),
    // 健康预见
    JK("jk.brand", "jk-merchant.brand", "jk-admin.brand", 16),
    // 叙州
    XZ("xz.brand", "xz-merchant.brand", "xz-admin.brand", 10),
    // 普宁
    PN("pn.brand", "pn-merchant.brand", "pn-admin.brand", 12),
    // 邻水
    LS("ls.brand", "ls-merchant.brand", "ls-admin.brand", 15),
    // 绿领在线
    LL("ll.brand", "ll-merchant.brand", "ll-admin.brand", 13),
    // 小安生活
    XASH("xash.brand", "xash-merchant.brand", "xash-admin.brand", 17),
    // 致富包
    ZFB("zfb-front", "zfb-platform", "zfb-platform", 0),
    // 筑码国稷
    ZMGJ("zmgj.brand", "zmgj-merchant.brand", "zmgj-admin.brand", 18),
    // 测试品牌商
    TEST("brand-test.brand", "brand-test-merchant", "brand-test-admin", 6),
    // 测试总平台
    TEST_PLATFORM("zfb-test.brand", "zfb-test-merchant", "zfb-test-admin", 0),
    //民生赋能
    MSFN("msfn.brand", "msfn-merchant.brand", "msfn-admin.brand", 19),
    ;
    // 前端地址
    private final String front;
    // 商户端地址
    private final String merchant;
    // 管理后台地址
    private final String admin;

    private final Integer id;

    BrandEnum(String front, String merchant, String admin, Integer id) {
        this.front = front;
        this.merchant = merchant;
        this.admin = admin;
        this.id = id;
    }

    public String getFront() {
        return front;
    }

    public String getMerchant() {
        return merchant;
    }

    public String getAdmin() {
        return admin;
    }

    /**
     * 根据url获取品牌商id
     * @param url
     * @return
     */
    public static Integer getId(String url) {
        for (BrandEnum typeEnum : BrandEnum.values()) {
            if (url.contains(typeEnum.getFront()) || url.contains(typeEnum.getMerchant()) || url.contains(typeEnum.getAdmin())) {
                return typeEnum.id;
            }
        }
        // 如果是本地直接获取idea vm环境变量中的值
        if (url.contains("localhost") || url.contains("127.0.0.1")) {
            String brandId = System.getProperty("BRANDID");
            if (StrUtil.isNotBlank(brandId)) {
                return Integer.parseInt(brandId);
            }
        }
        return 0;
    }

    /**
     * 判断是否是崇仁品牌商
     * @param url
     * @return
     */
    public static Boolean isCR(String url) {
        if (url.contains(BrandEnum.CR.getFront()) || url.contains(BrandEnum.CR.getMerchant()) || url.contains(BrandEnum.CR.getAdmin())) {
            return true;
        }
        return false;
    }

    /**
     * 判断是否是普宁品牌商
     * @param url
     * @return
     */
    public static Boolean isPN(String url) {
        if (url.contains(BrandEnum.PN.getFront()) || url.contains(BrandEnum.PN.getMerchant()) || url.contains(BrandEnum.PN.getAdmin())) {
            return true;
        }
        return false;
    }

    /**
     * 判断是否是徐州品牌商
     * @param url
     * @return
     */
    public static Boolean isXZ(String url) {
        if (url.contains(BrandEnum.XZ.getFront()) || url.contains(BrandEnum.XZ.getMerchant()) || url.contains(BrandEnum.XZ.getAdmin())) {
            return true;
        }
        return false;
    }

}
